package com.wh.custom.controller;

import com.wh.basic.vo.AjaxResult;
import com.wh.custom.service.ICustomCustomertypeService;
import com.wh.custom.pojo.CustomCustomertype;
import com.wh.custom.dto.CustomCustomertypeQueryDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;

/**
* 后端接口类；
*/
@RestController
@RequestMapping("/customerType")
public class CustomTypeController {

    @Autowired
    public ICustomCustomertypeService customCustomertypeService;

    /**
     * 接口：添加或修改
     * @param customCustomertype 传递的实体
     * @return AjaxResult 响应给前端
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody CustomCustomertype customCustomertype) {
        if ( customCustomertype.getId() != null){
            customCustomertypeService.updateById(customCustomertype);
        }else{
            customCustomertypeService.save(customCustomertype);
        }
        return new AjaxResult();

    }

    /**
     * 接口：删除
     * @param id
     * @return AjaxResult 响应给前端
     */
    @DeleteMapping(value = "/{id}")
    public AjaxResult del(@PathVariable("id") Long id) {
        customCustomertypeService.removeById(id);
        return new AjaxResult();
    }

    /**
     * 接口：批量删除
     * @param ids
     * @return AjaxResult 响应给前端
     */
    @PatchMapping
    public AjaxResult patchDel(@RequestBody List<Long> ids) {
        customCustomertypeService.removeByIds(ids);
        return new AjaxResult();
    }

    /**
     * 接口：查询单个对象
     * @param id
     */
    @GetMapping("/{id}")
    public CustomCustomertype findOne(@PathVariable("id") Long id) {
        return customCustomertypeService.getById(id);
    }


    /**
     * 接口：查询所有
     * @return
     */
    @GetMapping
    public List<CustomCustomertype> findAll() {
        return customCustomertypeService.list();
    }


    /**
     * 接口：分页查询或高级查询
     * @param customCustomertypeQueryDto 查询对象
     * @return IPage<CustomCustomertype> 分页对象
     */
    @PostMapping
    public IPage<CustomCustomertype> findByPage(@RequestBody CustomCustomertypeQueryDto customCustomertypeQueryDto) {
        return customCustomertypeService.findByPage(customCustomertypeQueryDto);
    }
}
